<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://example.com/mytags" prefix="mytags"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入Bootstrap样式表 -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <title>个人区</title>
    <link rel="stylesheet" href="resources/css/user.css">
    <style>
        /* 设置整体背景 */
        body {
            background-image: url('resources/bigxi.jpg'); /* 替换为实际的背景图片路径 */
            background-size: cover;
            background-position: center center;
            background-repeat: no-repeat;
            background-attachment: fixed;
        }
        .custom-alert {
            position: fixed;
            top: 50px; /* 调整此处的数值来控制向下移动的距离 */
            z-index: 1000;
        }

/* 在你的样式表中添加 */
.orange-background {
    background-color: white;
}

.hidden {
	display: none;
}

.visible {
	display: block;
}

        /* 添加其他样式，根据需要自行调整 */
    </style>
    
    <link rel="stylesheet" type="text/css" href="<c:url value = "/resources/css/index.css"/>">
</head>

<body>

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg">
    <a class="navbar-brand" href="#">书影音</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item">
                <a class="nav-link" href="<c:url value = "/home"/>">首页 <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="<c:url value = "/book"/>">读书</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="<c:url value = "/movie"/>">影视</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="<c:url value = "/music"/>">音乐</a>
            </li>
				<li class="nav-item"><a class="nav-link"
					href="<c:url value = "/filter"/>">筛选</a></li>	
            <li class="nav-item active">
                <a class="nav-link" href="<c:url value = "/user"/>">我的</a>
            </li>
        </ul>
        <c:if test="${not empty sessionScope.user}">
            	<a class="nav-link" style="color:white"
					href="<c:url value = "/user"/>">欢迎您，${user.username }</a>
       	 </c:if>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="search" placeholder="搜索" aria-label="搜索">
            <button class="btn btn-outline-light my-2 my-sm-0" type="submit">搜索</button>
        </form>
    </div>
</nav>


<c:if test="${message == false}">  
<div class=" d-flex justify-content-center">
<div class="alert alert-warning alert-dismissible fade show custom-alert" role="alert" style="z-index:1000">
  <strong>警告！</strong>用户名已存在。
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div> 	
</div>
</c:if>

<c:if test="${message == true}">  
<div class=" d-flex justify-content-center">
<div class="alert alert-info alert-dismissible fade show custom-alert" role="alert" style="z-index:1000">
	注册成功！请重新登录。
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div> 	
</div>
</c:if>

<c:if test="${loginmessage == false}">  
<div class=" d-flex justify-content-center">
<div class="alert alert-warning alert-dismissible fade show custom-alert" role="alert" style="z-index:1000">
	用户名或密码错误！
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
</div>
</c:if>

<!-- 登录表单 -->
<div id="LoginContainer" class="visible">
<div class="container">
    <div class="row">
        <div class="col-md-6 offset-md-7" style="top: 100px;">
            <div class="card mt-5">
                <div class="card-header">
                    <h4>Login</h4>
                </div>
                <div class="card-body">
                    <form action="<c:url value="/checkUser"/>" method="post">
                        <mytags:loginPage />
                    <div class="form-group form-check">
    					<input type="checkbox" class="form-check-input" id="exampleCheck1" name="rememberme">
    					<label class="form-check-label" for="exampleCheck1">记住我</label>
  					</div>
                    <div class="row justify-content-around">
                    <div class="col-3">
                    <button type="submit" class="btn btn-primary" >登陆</button>
                    </div>
                    <div class="col-3">
                    <button type="button" class="btn btn-primary" onclick="toggleVisibility()">注册</button>
                    </div>
                    </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<!-- 注册表单 -->
<div id="RegisterContainer" class="hidden">
<div class="container">
    <div class="row">
        <div class="col-md-6 offset-md-7" style="top: 100px;">
            <div class="card mt-5">
                <div class="card-header">
                    <h4>Register</h4>
                </div>
                <div class="card-body">
                    <form action="<c:url value="addUser"/>" method="post" onsubmit="return validateForm()">
                        <div class="form-group">
                            <label for="registerUsername">User name</label>
                            <input type="text" class="form-control" id="registerUsername" name="registerUsername" aria-describedby="emailHelp" placeholder="Enter User name">
                        </div>
                        <div class="form-group">
                            <label for="registerPassword">Password</label>
                            <input type="password" class="form-control" id="registerPassword" name="registerPassword" placeholder="Password">
                        </div>
                        <div class="form-group">
                            <label for="registerConfirmPassword">Confirm Password</label>
                            <input type="password" class="form-control" id="registerConfirmPassword" name="registerConfirmPassword" placeholder="Confirm Password">
                        </div>
                    <div class="row justify-content-around">
                    <div class="col-3">
                    <button type="submit" class="btn btn-success">注册</button>
                    </div>
                    <div class="col-3">
                    <button type="button" class="btn btn-success" onclick="toggleVisibility()">返回</button>
                    </div>
                    </div>
                    </form>
                    </div>
            </div>
        </div>
    </div>
</div>
</div>


<!-- 提示模态框 -->
<div class="modal" id="SuccessModal">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- 模态框头部 -->
      <div class="modal-header">
        <h3 class="modal-title">提示</h3>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>
      <!-- 模态框主体 -->
      <div class="modal-body">
        <h4>${message }注册成功！</h4>
        <h4>请重新登陆。</h4>
      </div>
    </div>
  </div>
</div>

<br>
<br>
    <div class="fixed-bottom">
        	<footer class=" text-center py-3"> &copy;
		2023 书影音 </footer>
    </div>

<!-- 引入Bootstrap的JavaScript和Popper.js，用于处理导航栏的交互效果 -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
    function toggleVisibility() {
        var Lcontainer = document.getElementById('LoginContainer');
        if (Lcontainer.classList.contains('hidden')) {
            Lcontainer.classList.remove('hidden');
            Lcontainer.classList.add('visible');
        } else if (Lcontainer.classList.contains('visible')){
            Lcontainer.classList.remove('visible');
            Lcontainer.classList.add('hidden');
        }
        
        var Rcontainer = document.getElementById('RegisterContainer');
        if (Rcontainer.classList.contains('hidden')) {
            Rcontainer.classList.remove('hidden');
            Rcontainer.classList.add('visible');
        } else if (Rcontainer.classList.contains('visible')){
            Rcontainer.classList.remove('visible');
            Rcontainer.classList.add('hidden');
        }
    }
    
    function validateForm() {
        var username = document.getElementById("registerUsername").value;
        var password = document.getElementById("registerPassword").value;
        var confirmpassword = document.getElementById("registerConfirmPassword").value;
        
        if (username.trim() === "" || username.length < 4) {
            alert("用户名不能为空且长度必须大于3");
            return false; // 阻止表单提交
        }
        
        if (password.trim() === "" || password.length < 5) {
        	alert("密码不能为空且长度必须大于等于5");
        	return false;
        } else if (password.trim() === confirmpassword.trim()) {
    		toggleVisibility();
    		showModel("successful");
        	return true;
        } else {
        	alert("两次密码需一致");
        	return false;
        }
    }
</script>

</body>
</html>